from flask import Flask, jsonify, request, render_template
import requests

app = Flask(__name__)

students = []

@app.route('/') # 获取学生信息页面
def index():
    return render_template('index.html')

@app.route('/jquery') # 获取学生信息页面
def jquery():
    return render_template('jquery.html')

@app.route('/ajax') # 获取学生信息页面
def ajax():
    url = "https://www.hceb.edu.cn/xwzx/xxxw.htm"
    source_code = ''
    try:
        response = requests.get(url)
        if response.status_code == 200:
            response.encoding = 'utf-8'
            source_code = response.text  # 将获取到的源代码存储到变量中         
        else:
            print("请求失败:", response.status_code)
    except Exception as e:
        print("发生异常:", e)

    return render_template('ajax.html', source_code=source_code)  # 将源代码传递给模板

@app.route('/promise') # 获取学生信息页面
def promise():
    return render_template('promise.html')

@app.route('/await') # 获取学生信息页面
def wait():
    return render_template('await.html')

@app.route('/login', methods=['GET', 'POST'])
def login():
    message = ''
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        # 在这里可以添加验证用户名和密码的逻辑，比如检查数据库中的用户信息是否匹配
        if username == 'user' and password == 'password':
            message = '登录成功'
        else:
            message = '用户名或密码错误'

    return render_template('login.html', message=message)

@app.route('/store',methods=['get']) # 获取学生信息页面
def store():
    return render_template('store.html')

@app.route('/addStu',methods=['post']) # 获取学生信息页面
def addStu():
    stu = eval(request.data.decode('utf-8'))
    print(stu)
    students.append(stu)

    print(students)
    return 'haha'

@app.route('/students') # 获取学生信息页面
def getStudents():
    return students

if __name__ == '__main__':
    app.run(debug=True,host='0.0.0.0',port=80)


